
const addZero = num => {
  if (parseInt(num) < 10) {
    num = '0' + num
  }
  return num
}
const getYYYYMMDD = str => {
  let nDate = new Date(str)
  // nDate = new Date(nDate.getTime() + nDate.getTimezoneOffset() * 60000);
  let nYear = nDate.getFullYear()
  let nMonth = nDate.getMonth() + 1
  let nDay = nDate.getDate()
  let nHours = nDate.getHours()
  let nMinutes = nDate.getMinutes()
  let nSeconds = nDate.getSeconds()
  let nTime = nYear + '-' + addZero(nMonth) + '-' + addZero(nDay) // YYYY-MM-DD
  let nTimes = nYear + '年' + addZero(nMonth) + '月' + addZero(nDay) + '日'
  let nDateTime = nTime + ' ' + addZero(nHours) + ':' + addZero(nMinutes) + ':' + addZero(nSeconds) // YYYY-MM-DD-MM-SS
  let dTime = addZero(nMonth) + '. ' + addZero(nDay) + ' ' + addZero(nHours) + ':' + addZero(nMinutes)
  return {
    nTime: nTime, // 格式为 YYYY-MM-DD
    nTimes: nTimes,
    nDateTime: nDateTime, // 格式为 YYYY-MM-DD-HH-MM-SS
    dTime: dTime
  }
}
const getDate = str => {
  if (!str) {
    return {
      dTime: '', // MM-DD HH:MM,
      nTime: '', // 格式为 YYYY-MM-DD
      nTimes: ''
    }
  }
  let msg = str.split(' ')
  let t1 = msg[0].split('-')
  let t2 = msg[1].split(':')
  let dTime = t1[1] + '. ' + t1[2] + ' ' + t2[0] + ':' + t2[1]
  let nTime = t1[0] + '-' + t1[1] + '-' + t1[2]
  let nTimes = t1[0] + '年' + t1[1] + '月' + t1[2] + '日'
  return {
    dTime: dTime, // MM-DD HH:MM,
    nTime: nTime, // 格式为 YYYY-MM-DD
    nTimes: nTimes
  }
}
//获取cookie、
// const getCookie(name) {
//  var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
//  if (arr = document.cookie.match(reg))
//   return (arr[2]);
//  else
//   return null;
// }

// //设置cookie,增加到vue实例方便全局调用
// const setCookie (c_name, value, expiredays) {
//  var exdate = new Date();
//  exdate.setDate(exdate.getDate() + expiredays);
//  document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
// };

// //删除cookie
// const delCookie (name) {
//  var exp = new Date();
//  exp.setTime(exp.getTime() - 1);
//  var cval = getCookie(name);
//  if (cval != null)
//   document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString();
// };
module.exports = {
  getYYYYMMDD: getYYYYMMDD,
  getDate: getDate,
  // getCookie,
  // delCookie,
  // delCookie
}
